{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b5592b33-b18b-436d-b561-93cd92c684f8",
   "metadata": {},
   "source": [
    "饼图"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8fe58a1b-cf62-4995-8eb3-8b9caa7e2cb9",
   "metadata": {},
   "source": [
    "基本饼图\r\n",
    "环形饼图\r\n",
    "多饼图\r\n",
    "玫瑰图"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cd450685-498a-4415-979b-f059b4b99fdc",
   "metadata": {},
   "source": [
    "【1】"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "231e589a-f00d-40a5-b7f7-d895ae41beaa",
   "metadata": {},
   "source": [
    "基本饼图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "7cbfca60-8940-41d5-a014-ab4a42c2eb5a",
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import Pie\n",
    "data_pair = [(\"Category A\", 10), (\"Category B\", 20), (\"Category C\", 30),\n",
    "             (\"Category D\", 40), (\"Category E\", 50), (\"Category F\", 60),\n",
    "             (\"Category G\", 70)]\n",
    "c = (\n",
    "    Pie()\n",
    "    .add(\"\", data_pair)\n",
    "    .set_global_opts(title_opts=opts.TitleOpts(title='Pie'))\n",
    "    .set_series_opts(label_opts=opts.LabelOpts(formatter=\"{b}:{c}\"))\n",
    "    .render(\"饼图.html\")\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "2d3e029c-1071-43d7-b32a-2beed466fabe",
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "not enough values to unpack (expected 2, got 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[3], line 7\u001b[0m\n\u001b[0;32m      2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mpyecharts\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m options \u001b[38;5;28;01mas\u001b[39;00m opts\n\u001b[0;32m      3\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mpyecharts\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mfaker\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m Faker\n\u001b[0;32m      5\u001b[0m c \u001b[38;5;241m=\u001b[39m (\n\u001b[0;32m      6\u001b[0m     Pie()\n\u001b[1;32m----> 7\u001b[0m     \u001b[38;5;241m.\u001b[39madd(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m\"\u001b[39m, [\u001b[38;5;28mlist\u001b[39m[z] \u001b[38;5;28;01mfor\u001b[39;00m z \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mzip\u001b[39m(Faker\u001b[38;5;241m.\u001b[39mchoose(),Faker\u001b[38;5;241m.\u001b[39mvalues())])\n\u001b[0;32m      8\u001b[0m     \u001b[38;5;66;03m# 注意！ 这里添加颜色是已经确认了Faker源代码中不管怎么遍历，随机会出现7个数据（pycharm查看源代码ctrl+鼠标左键 点进去看）\u001b[39;00m\n\u001b[0;32m      9\u001b[0m     \u001b[38;5;241m.\u001b[39mset_colors([\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mblue\u001b[39m\u001b[38;5;124m\"\u001b[39m,\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mgreen\u001b[39m\u001b[38;5;124m\"\u001b[39m,\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124myellow\u001b[39m\u001b[38;5;124m\"\u001b[39m,\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mred\u001b[39m\u001b[38;5;124m\"\u001b[39m,\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpink\u001b[39m\u001b[38;5;124m\"\u001b[39m,\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124morange\u001b[39m\u001b[38;5;124m\"\u001b[39m,\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpurple\u001b[39m\u001b[38;5;124m\"\u001b[39m])\n\u001b[0;32m     10\u001b[0m     \u001b[38;5;241m.\u001b[39mset_global_opts(title_opts\u001b[38;5;241m=\u001b[39mopts\u001b[38;5;241m.\u001b[39mTitleOpts(title\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mPie-设置颜色\u001b[39m\u001b[38;5;124m'\u001b[39m))\n\u001b[0;32m     11\u001b[0m     \u001b[38;5;241m.\u001b[39mset_series_opts(label_opts\u001b[38;5;241m=\u001b[39mopts\u001b[38;5;241m.\u001b[39mLabelOpts(formatter\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{b}\u001b[39;00m\u001b[38;5;124m:\u001b[39m\u001b[38;5;132;01m{c}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m))\n\u001b[0;32m     12\u001b[0m     \u001b[38;5;241m.\u001b[39mrender(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m设置颜色的饼图1.html\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m     13\u001b[0m )\n",
      "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python312\\site-packages\\pyecharts\\charts\\basic_charts\\pie.py:56\u001b[0m, in \u001b[0;36mPie.add\u001b[1;34m(self, series_name, data_pair, color, color_by, is_legend_hover_link, selected_mode, selected_offset, radius, center, rosetype, is_clockwise, start_angle, min_angle, min_show_label_angle, is_avoid_label_overlap, is_still_show_zero_sum, percent_precision, is_show_empty_circle, empty_circle_style_opts, label_opts, label_line_opts, tooltip_opts, itemstyle_opts, emphasis_opts, encode, markpoint_opts, markline_opts, markarea_opts)\u001b[0m\n\u001b[0;32m     54\u001b[0m     data \u001b[38;5;241m=\u001b[39m data_pair\n\u001b[0;32m     55\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m---> 56\u001b[0m     data \u001b[38;5;241m=\u001b[39m [{\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mname\u001b[39m\u001b[38;5;124m\"\u001b[39m: n, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mvalue\u001b[39m\u001b[38;5;124m\"\u001b[39m: v} \u001b[38;5;28;01mfor\u001b[39;00m n, v \u001b[38;5;129;01min\u001b[39;00m data_pair]\n\u001b[0;32m     58\u001b[0m     \u001b[38;5;28;01mfor\u001b[39;00m a, _ \u001b[38;5;129;01min\u001b[39;00m data_pair:\n\u001b[0;32m     59\u001b[0m         \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39moptions\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mlegend\u001b[39m\u001b[38;5;124m\"\u001b[39m)[\u001b[38;5;241m0\u001b[39m]\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mdata\u001b[39m\u001b[38;5;124m\"\u001b[39m)\u001b[38;5;241m.\u001b[39mappend(a)\n",
      "\u001b[1;31mValueError\u001b[0m: not enough values to unpack (expected 2, got 1)"
     ]
    }
   ],
   "source": [
    "from pyecharts.charts import Pie\n",
    "from pyecharts import options as opts\n",
    "from pyecharts.faker import Faker\n",
    "\n",
    "c = (\n",
    "    Pie()\n",
    "    .add(\"\", [list[z] for z in zip(Faker.choose(),Faker.values())])\n",
    "    # 注意！ 这里添加颜色是已经确认了Faker源代码中不管怎么遍历，随机会出现7个数据（pycharm查看源代码ctrl+鼠标左键 点进去看）\n",
    "    .set_colors([\"blue\",\"green\",\"yellow\",\"red\",\"pink\",\"orange\",\"purple\"])\n",
    "    .set_global_opts(title_opts=opts.TitleOpts(title='Pie-设置颜色'))\n",
    "    .set_series_opts(label_opts=opts.LabelOpts(formatter=\"{b}:{c}\"))\n",
    "    .render(\"设置颜色的饼图1.html\")\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2723a5d3-6453-49db-a693-e2586513838a",
   "metadata": {},
   "source": [
    "在你的代码中，问题出现在尝试将 zip(Faker.choose(), Faker.values()) 的结果解包为两个值的元组列表。然而，zip 函数会根据最短的输入序列停止迭代，这意味着如果 Faker.choose() 和 Faker.values() 返回的列表长度不同，zip 的结果长度将等于较短的那个列表。此外，你的列表推导式 [list[z] for z in zip(Faker.choose(), Faker.values())] 也是不正确的，因为 list 是一个类型，而不是一个函数或变量，你应该直接写 [z for z in ...]。\r",
    "\r\n",
    "另外，Faker.choose() 和 Faker.values() 通常返回的是单个列表，而不是两个可以配对使用的列表。你需要确保这两个函数返回的数据可以正确地配对为 (name, value) 对。但是，根据 pyecharts.faker 的常规用法，这些函数通常不是设计来直接这样使用的。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "b9b61175-474c-46b9-856c-68b0b3ab890b",
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyecharts.charts import Pie\n",
    "from pyecharts import options as opts\n",
    "\n",
    "# 创建一个简单的数据对列表\n",
    "data_pair = [(\"Category A\", 10), (\"Category B\", 20), (\"Category C\", 30),\n",
    "             (\"Category D\", 40), (\"Category E\", 50), (\"Category F\", 60),\n",
    "             (\"Category G\", 70)]\n",
    "\n",
    "# 创建饼图\n",
    "c = (\n",
    "    Pie()\n",
    "    .add(\"\", data_pair)\n",
    "    .set_colors([\"blue\", \"green\", \"yellow\", \"red\", \"pink\", \"orange\", \"purple\"])\n",
    "    .set_global_opts(title_opts=opts.TitleOpts(title='Pie-设置颜色'))\n",
    "    .set_series_opts(label_opts=opts.LabelOpts(formatter=\"{b}:{c}\"))\n",
    "    .render(\"设置颜色的饼图.html\")\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "580d2484-5973-4843-8e79-ec61696337f7",
   "metadata": {},
   "source": [
    "【2】"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "952cbbf8-80e3-4a0d-974a-72010e3c4e0c",
   "metadata": {},
   "source": [
    "带样式的饼图"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c46ea037-534e-4938-9f5e-43d1da416bef",
   "metadata": {},
   "source": [
    "环形饼图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "405f94ec-b363-4df5-b9a3-5ddcc3f284ff",
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import Pie\n",
    "data_pair = [(\"Category A\", 10), (\"Category B\", 20), (\"Category C\", 30),\n",
    "             (\"Category D\", 40), (\"Category E\", 50), (\"Category F\", 60),\n",
    "             (\"Category G\", 70)]\n",
    "c = (\n",
    "    Pie()\n",
    "    .add(\"\", data_pair,radius=['30%','80%'])\n",
    "    .set_global_opts(title_opts=opts.TitleOpts(title='Pie'))\n",
    "    .set_series_opts(label_opts=opts.LabelOpts(formatter=\"{b}:{c}\"))\n",
    "    .render(\"环形饼图.html\")\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "216a77f1-aa5f-45b5-8f63-08295abcad2b",
   "metadata": {},
   "source": [
    "【3】"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3b9b5587-d4ed-4be3-bd9e-e5e31f6e21bb",
   "metadata": {},
   "source": [
    "玫瑰图（南丁格尔图）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "aca1ac5b-fc82-4e67-a954-669d49cb2e72",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'D:\\\\jupyter\\\\带自定义样式的圆环图.html'"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from pyecharts.charts import Pie  # 导入饼图\n",
    "from pyecharts.faker import Faker # pyecharts库中自带的假数据\n",
    "from pyecharts.globals import ThemeType\n",
    "\n",
    "# 自定义样式\n",
    "itemstyle = {\n",
    "    \"normal\":{\n",
    "        'borderRadius':15,\n",
    "        'borderWidth':5,\n",
    "        'borderColor':'auto'\n",
    "    }\n",
    "}\n",
    "va = [65,56,48,43,30,25,12]\n",
    "value = [list(z) for z in zip(Faker.choose(),va)]\n",
    "pie = (\n",
    "    Pie(init_opts=opts.InitOpts(theme=ThemeType.CHALK))\n",
    "    .add(\n",
    "         series_name='',\n",
    "         data_pair=value,\n",
    "         radius=['30%','80%'], # 饼图的内半径和外半径 因为是圆环，所有一定会有内半径\n",
    "         # 注意这个不是上一个程序中的center=['75%','75%'],center指的是基于画布的定位，而这个是radius半径\n",
    "         rosetype='area', # 展示形成 南丁格尔 图\n",
    "         label_opts=opts.LabelOpts(formatter=\"{b}:{c}\\n百分比{d}%\"), # 标签配置\n",
    "         itemstyle_opts=itemstyle,\n",
    "         emphasis_opts=opts.EmphasisOpts(is_show_label_line=True,focus='series',\n",
    "                                        label_opts=opts.LabelOpts(font_size=20,font_weight='bold')), # 高亮多边形配置\n",
    "        )\n",
    "    .set_global_opts(tooltip_opts=opts.TooltipOpts(trigger='item'))\n",
    ")\n",
    "pie.options['series'][0]['padAngle']=1, # 假设每个饼图各个饼块之间的距离为1\n",
    "pie.render('带自定义样式的圆环图.html')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "24fff04b-0716-408b-af5a-22c0b5a65a00",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'D:\\\\jupyter\\\\带自定义样式的圆环图1.html'"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from pyecharts.charts import Pie  # 导入饼图\n",
    "from pyecharts.faker import Faker # pyecharts库中自带的假数据\n",
    "from pyecharts.globals import ThemeType\n",
    "\n",
    "# 自定义样式\n",
    "itemstyle = {\n",
    "    \"normal\":{\n",
    "        'borderRadius':15,\n",
    "        'borderWidth':5,\n",
    "        'borderColor':'auto'\n",
    "    }\n",
    "}\n",
    "va = [65,56,48,43,30,25,12]\n",
    "value = [list(z) for z in zip(Faker.choose(),va)]\n",
    "pie = (\n",
    "    Pie(init_opts=opts.InitOpts(theme=ThemeType.CHALK))\n",
    "    .add(\n",
    "         series_name='',\n",
    "         data_pair=value,\n",
    "         radius=['30%','80%'], # 饼图的内半径和外半径 因为是圆环，所有一定会有内半径\n",
    "         # 注意这个不是上一个程序中的center=['75%','75%'],center指的是基于画布的定位，而这个是radius半径\n",
    "         rosetype='area', # 展示形成 南丁格尔 图\n",
    "         emphasis_opts=opts.EmphasisOpts(is_show_label_line=True,focus='series',\n",
    "                                        label_opts=opts.LabelOpts(font_size=20,font_weight='bold')), # 高亮多边形配置\n",
    "        )\n",
    "    .set_global_opts(tooltip_opts=opts.TooltipOpts(trigger='item'))\n",
    "    .set_series_opts(itemstyle_opts=itemstyle,\n",
    "                     label_opts=opts.LabelOpts(formatter=\"{b}:{c}\\n百分比{d}%\"), # 图表样式配置\n",
    "                    )\n",
    ")\n",
    "pie.options['series'][0]['padAngle']=1, # 假设每个饼图各个饼块之间的距离为1\n",
    "pie.render('带自定义样式的圆环图1.html')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b4c782d9-2417-4027-b9d6-94613d224f4e",
   "metadata": {},
   "source": [
    "【4】"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c70f60d6-9c80-497d-b163-19ae59bdd969",
   "metadata": {},
   "source": [
    "多饼图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "9b0db487-824c-403b-a1c8-caea8e36571b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'D:\\\\jupyter\\\\饮料饼图.html'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import Pie\n",
    "\n",
    "c = (\n",
    "    Pie()\n",
    "    .add_dataset(\n",
    "        source=[\n",
    "            [\"产品\",\"2012\",\"2013\",\"2014\",\"2015\",\"2016\",\"2017\"],\n",
    "            [\"拿铁\",41.1,30.4,65.1,53.3,83.8,98.7],\n",
    "            [\"奶茶\",32.4,85.5,65.3,45.6,55.2,63.4],\n",
    "            [\"芝士可可\",24.1,26.3,28.6,29.4,30.5,18.6],\n",
    "            [\"大红袍\",55.5,24.8,65.2,75.4,64.2,34.5]\n",
    "        ]\n",
    "    )\n",
    "    # 添加一个名为‘拿铁’的饼图系列，数据对（data_pair）为空\n",
    "    # 半径为60\n",
    "    # 中心位置再画布的25%宽度处和30%高度处\n",
    "    # encode参赛指定了数据中产品字段作为项目名称，2012字段作为值\n",
    "    .add(\n",
    "        series_name=\"拿铁\",\n",
    "        data_pair=[],\n",
    "        # radius参数值指的是饼图系列的半径大小，它决定了饼图的大小，即饼图从其中心到边缘的距离\n",
    "        # 60 这个值通常相对于某个基准的百分比（如画布大小），或绝对值像素值，具体取决于图标库，基本当前画布基准的60%\n",
    "        radius=60,\n",
    "        center=[\"25%\",\"30%\"], # 饼图中心位于画布宽度的25%处和画布高度的30%处，类似于定位\n",
    "        encode={\"itemName\":\"产品\",\"value\":\"2012\"}\n",
    "    )\n",
    "    .add(\n",
    "        series_name=\"奶茶\",\n",
    "        data_pair=[],\n",
    "        radius=60,\n",
    "        center=[\"75%\",\"30%\"],\n",
    "        encode={\"itemName\":\"产品\",\"value\":\"2013\"}\n",
    "    )\n",
    "    .add(\n",
    "        series_name=\"芝士可可\",\n",
    "        data_pair=[],\n",
    "        radius=60,\n",
    "        center=[\"25%\",\"75%\"],\n",
    "        encode={\"itemName\":\"产品\",\"value\":\"2014\"}\n",
    "    )\n",
    "    .add(\n",
    "        series_name=\"大红袍\",\n",
    "        data_pair=[],\n",
    "        radius=60,\n",
    "        center=[\"75%\",\"75%\"],\n",
    "        encode={\"itemName\":\"产品\",\"value\":\"2015\"}\n",
    "    )\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title=\"饮料\"),\n",
    "        legend_opts=opts.LegendOpts(pos_left=\"30%\",pos_top=\"2%\")\n",
    "    )\n",
    "    \n",
    ")\n",
    "c.render(\"饮料饼图.html\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ba2a157e-0700-4717-826b-74432174cdb7",
   "metadata": {},
   "source": [
    "【5】"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6fbd95b5-3f68-4876-8b98-aa6ee7ed7bb8",
   "metadata": {},
   "source": [
    "组合饼图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "d898c4a2-9a38-4ffa-a347-3db5ad2efaee",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'D:\\\\jupyter\\\\组合饼图.html'"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from pyecharts.charts import Pie  # 导入饼图\n",
    "from pyecharts.faker import Faker # pyecharts库中自带的假数据\n",
    "from pyecharts.globals import ThemeType\n",
    "import pandas as pd\n",
    "\n",
    "data = pd.read_excel('./data/icu.xlsx')\n",
    "data\n",
    "dp1 = data[['国家', 'ICU人均']].values.tolist()\n",
    "dp2 = data[['国家', 'ICU总数']].values.tolist()\n",
    "dp3 = data[['国家', '确诊患者']].values.tolist()\n",
    "dp4 = data[['国家', '死亡人数']].values.tolist()\n",
    "\n",
    "# 自定义样式\n",
    "itemstyle = {\n",
    "    \"normal\":{\n",
    "        'borderRadius':15,\n",
    "        'borderWidth':5,\n",
    "        'borderColor':'auto'\n",
    "    }\n",
    "}\n",
    "'''\n",
    "va = [65,56,48,43,30,25,12]\n",
    "value = [list(z) for z in zip(Faker.choose(),va)]\n",
    "'''\n",
    "pie = (\n",
    "    Pie(init_opts=opts.InitOpts(theme=ThemeType.CHALK))\n",
    "    .add(\n",
    "        series_name=\"ICU人均\",\n",
    "        data_pair=dp1,\n",
    "        radius=[40,80], # 饼图的内半径和外半径\n",
    "        center=[\"25%\",\"30%\"], # 饼图中心位于画布宽度的25%处和画布高度的30%处，类似于定位\n",
    "    )\n",
    "    .add(\n",
    "        series_name=\"ICU总数\",\n",
    "        data_pair=dp2,\n",
    "        radius=[40,80],\n",
    "        center=[\"75%\",\"30%\"],\n",
    "    )\n",
    "    .add(\n",
    "        series_name=\"确诊患者\",\n",
    "        data_pair=dp3,\n",
    "        radius=[40,80],\n",
    "        center=[\"25%\",\"75%\"],\n",
    "    )\n",
    "    .add(\n",
    "        series_name=\"死亡人数\",\n",
    "        data_pair=dp4,\n",
    "        radius=[40,80],\n",
    "        center=[\"75%\",\"75%\"],\n",
    "    )\n",
    "    .set_global_opts(\n",
    "        tooltip_opts=opts.TooltipOpts(trigger='item'),\n",
    "        title_opts=[\n",
    "            dict(text='ICU人均',top='28%',left='20%'),\n",
    "            dict(text='ICU总数',top='28%',left='70%'),\n",
    "            dict(text='确诊患者',top='75%',left='20%'),\n",
    "            dict(text='死亡人数',top='75%',left='70%'),\n",
    "            dict(text='部分国家病例人数与ICU数据对比饼图',left='center')\n",
    "        ],\n",
    "        legend_opts=opts.LegendOpts(pos_top=\"2%\",\n",
    "                                    textstyle_opts=opts.TextStyleOpts(color='white'))\n",
    "    )\n",
    "    .set_series_opts(itemstyle_opts=itemstyle,\n",
    "                     label_opts=opts.LabelOpts(formatter=\"{b}:{c}\\n百分比{d}%\"), # 图表样式配置\n",
    "                    )\n",
    ")\n",
    "pie.options['series'][0]['padAngle']=1, # 假设每个饼图各个饼块之间的距离为1\n",
    "pie.render('组合饼图.html')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
